const $api = require('./../../utils/request').API;
const filter = require('../../utils/loginCheck');
Page(filter.loginCheck({

  data: {
    info: {},
    projectList:[],
    show: false,
    dayList:[],
    thisTime:'',
    radio:'',
    time:'',
    reserveNo:'',
    projectId:''
  },

  onClose() {
    this.setData({ show: false })
  },

  imgPreview(event) {
    wx.previewImage({
      current: event.currentTarget.dataset.url,
      urls: [this.data.info.yuanGongZhaoPianPathReal]
    })
  },

  async getInfo(id) {
    const { tStaff } = await $api.getStaffInfo(id);
    const { page } = await $api.getProjectList();
    this.setData({
      info: tStaff
    });
    let arr = [];
    page.list.forEach(e=>{
      this.data.info.list.forEach(element=>{
        if( e.id == element ){
          arr.push(e);
        }
      })
    })
    this.setData({
      projectList:arr
    })
    wx.setNavigationBarTitle({
      title: `${this.data.info.gongHao}号员工`
    })
  },


  GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);
    var m = dd.getMonth()+1;//获取当前月份的日期
    var d = dd.getDate();
    return m+"-"+d;
},
GetThisTime(){
  var dd = new Date();
  dd.setDate(dd.getDate());
  var hh = dd.getHours();
  var mm = dd.getMinutes();
  return hh+":"+mm;
},
onChange(e){
  this.setData({
    radio:e.detail
  })
},
bindTimeChange(e){
  this.setData({
    time: e.detail.value
  })
},

  onLoad: function (options) {
    this.getInfo(options.id);

    this.setData({
      dayList:[this.GetDateStr(0),this.GetDateStr(1),this.GetDateStr(2)],
      thisTime:this.GetThisTime()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  yuyue(e) {
    this.setData({ show: true,
    projectId:e.currentTarget.dataset.project
    })
    this.getReserveNo();
    
  },

  submit(e){
    var date=new Date;
   var year = date.getFullYear();
   
    let params = {
      "arriveTime":  year +'-'+ this.data.radio +' '+ this.data.thisTime+':00',
      "jishiCodes": this.data.info.gongHao,
      "openId":wx.getStorageSync('openid'),
      "projectId": this.data.projectId,
      "yuyueNo": this.data.reserveNo
    }
    $api.yuyue(params).then(res=>{
      console.log(res);
      if(res.code == 200){
        wx.showToast({
          title: '预约成功',
          icon:'success'
        })
        this.setData({
          show:false
        })
      }else{
        wx.showToast({
          title: '预约失败',
          icon:none
        })
      }
    })
 


    // yuyue
    /*

    */
  },

  getReserveNo(){
    $api.getReserveNo().then(res=>{
      this.setData({
        reserveNo:res.data
      })
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '测试标题1111',
      path: '/pages/home/home',
      imageUrl: 'https://pics2.baidu.com/feed/09fa513d269759ee054dbe1d94fba9136c22dfc9.png?token=03927bb6da8cc0fe20ce486ca947b582&s=9B141CC6105327D009FD992D0300304B'
    }
  }
}))